<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: lb
  Date: 15-12-21
  Time: 下午1:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>批量添加</title>
    <script src="/static/datepicker/WdatePicker.js"></script>
</head>
<body>
<div>
    <h3>请选择度假屋</h3>
    <c:forEach items="${houseInfoDTOs}" var="houseInfoDTO">
        &nbsp;&nbsp;${houseInfoDTO.name}<input type="checkbox" value="${houseInfoDTO.guid}"/>&nbsp;&nbsp;
    </c:forEach>
</div>
<br/>

<div style="width:1080px">
    <div class="panel panel-default">
        <div class="panel-heading">黄金周</div>
        <div class="panel-body">
            <div class="weekTime">
                <div class="weekH">
                    开始：<input type="text" class="times" id="addStartH"
                              onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'addEndH\');}'})">&nbsp;
                    结束：<input type="text" class="times" id="addEndH"
                              onFocus="WdatePicker({minDate:'#F{$dp.$D(\'addStartH\');}'})">
                </div>
                <a>添加黄金周时间段</a>
            </div>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">旺季周</div>
        <div class="panel-body">
            <div class="weekTime">
                <div class="weekW">
                    开始：<input type="text" class="times" id="addStartW"
                              onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'addEndW\');}'})">&nbsp;
                    结束：<input type="text" class="times" id="addEndW"
                              onFocus="WdatePicker({minDate:'#F{$dp.$D(\'addStartW\');}'})">
                </div>
                <a>添加旺季周时间段</a>
            </div>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">平季周</div>
        <div class="panel-body">
            <div class="weekTime">
                <div class="weekP">
                    开始：<input type="text" class="times" id="addStartP"
                              onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'addEndP\');}'})">&nbsp;
                    结束：<input type="text" class="times" id="addEndP"
                              onFocus="WdatePicker({minDate:'#F{$dp.$D(\'addStartP\');}'})">
                </div>
                <a>添加平季周时间段</a>
            </div>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">淡季周</div>
        <div class="panel-body">
            <div class="weekTime">
                <div class="weekD">
                    开始：<input type="text" class="times" id="addStartD"
                              onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'addEndD\');}'})">&nbsp;
                    结束：<input type="text" class="times" id="addEndD"
                              onFocus="WdatePicker({minDate:'#F{$dp.$D(\'addStartD\');}'})">
                </div>
                <a>添加淡季周时间段</a>
            </div>
        </div>
    </div>

</div>
<button class="submit">提交</button>
<script type="text/javascript">
    $(".weekTime a").on('click', function () {
        var randomtime = new Date().getTime();
        var s = "开始：<input type=\"text\" class=\"times\" id=\"addStartD" + randomtime + "\"" +
                "onFocus=\"WdatePicker({maxDate:'#F{$dp.$D(\\'addEndD" + randomtime + "\\');}'})\">&nbsp;" +
                "  结束：<input type=\"text\" class=\"times\" id=\"addEndD" + randomtime + "\"" +
                "onFocus=\"WdatePicker({minDate:'#F{$dp.$D(\\'addStartD" + randomtime + "\\');}'})\">";
        $(this).parents("div.weekTime").find("div").append(s)
    })
    $(".submit").on('click', function () {
        var guidsArray = [];
        var weekH = "", weekW = "", weekD = "", weekP = "", guids = "";
        $("input[type=checkbox]:checked").each(function () {
            guidsArray.push($(this).val())
        })
        if(guidsArray.length==0){
            alert("请勾线需要批量的度假屋");
            return false;
        }
        guids = guidsArray.join(",")
        $(".weekTime").each(function () {
            var getTimes = "";
            for (var i = 0; i < $(this).find("input[type=text].times").length; i++) {
                if ((i + 1) % 2 == 0) {
                    if ($(this).find("input[type=text].times").eq(i).val() != "") {
                        getTimes += $(this).find("input[type=text].times").eq(i).val() + ";";
                    }
                } else {
                    if ($(this).find("input[type=text].times").eq(i).val() != "") {
                        getTimes += $(this).find("input[type=text].times").eq(i).val() + ",";
                    }
                }
            }
            switch ($(this).find("div").attr("class")) {
                case "weekH":
                    weekH = getTimes;
                    break;
                case "weekW":
                    weekW = getTimes;
                    break;
                case "weekD":
                    weekD = getTimes;
                    break;
                case "weekP":
                    weekP = getTimes;
                    break;
            }
        })
        $.ajax({
            url: '/house_week/batchaddhouseweektime',
            type: 'POST',
            dataType: 'json',
            data: {guids: guids, weekH: weekH, weekW: weekW, weekP: weekP, weekD: weekD},
            success: function (data) {
                location.reload();
            }
        })
    })
</script>
</body>
</html>